package com.zx.lean_ui.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.zx.lean_ui.R;

import java.util.ArrayList;
import java.util.List;

public class ViewPagerAdapter extends RecyclerView.Adapter<ViewPagerAdapter.ViewPagerViewHolder> {
    private List<String>titles=new ArrayList<>();
    private List<Integer>colors=new ArrayList<>();

    public ViewPagerAdapter() {
        titles.add("hello");
        titles.add("邹欣");
        titles.add("康家慧");
        titles.add("吕阳阳");
        titles.add("王仪");
        colors.add(R.color.white);
        colors.add(R.color.YELLOW);
        colors.add(R.color.purple_500);
        colors.add(R.color.teal_200);
        colors.add(R.color.purple_200);
    }

    @NonNull
    @Override
    public ViewPagerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_pager,parent,false);
        ViewPagerViewHolder holder=new ViewPagerViewHolder(inflate);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewPagerAdapter.ViewPagerViewHolder holder, int position) {
        holder.mTv.setText(titles.get(position));
        holder.mContainer.setBackgroundResource(colors.get(position));

    }

    @Override
    public int getItemCount() {
        return 5;
    }

    class ViewPagerViewHolder extends RecyclerView.ViewHolder{
        TextView mTv;
        RelativeLayout mContainer;

        public ViewPagerViewHolder(@NonNull View itemView) {
            super(itemView);
            mContainer=itemView.findViewById(R.id.container);
            mTv=itemView.findViewById(R.id.tvTitle);

        }
    }
}
